package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.extension.api.R;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.lang.annotation.Retention;

/**
 * <p>
 *
 * </p>
 *
 * @author lzt
 * @version 1.0
 * @since 2024/4/9 上午11:25
 */
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Resource
    private WmMaterialService wmMaterialService;

    /**
     * 上传图片到minio
     * @param multipartFile
     * @return
     */
    @RequestMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        return wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 获取文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.findList(dto);
    }

    /**
     * 删除照片
     * @param id - 带删除的照片
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult del(@PathVariable("id") String id) {
        return wmMaterialService.del(id);
    }

    /**
     * 添加到收藏之中
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult Collect(@PathVariable("id") String id) {
        return wmMaterialService.cancelCollect(id,true);
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") String id) {
        return wmMaterialService.cancelCollect(id,false);
    }
}
